package org.jeecgframework.codegenerate.util;

import java.io.UnsupportedEncodingException;
import java.security.KeyFactory;
import java.security.KeyPair;
import java.security.KeyPairGenerator;
import java.security.MessageDigest;
import java.security.PrivateKey;
import java.security.PublicKey;
import java.security.SecureRandom;
import java.security.Signature;
import java.security.spec.PKCS8EncodedKeySpec;
import java.security.spec.X509EncodedKeySpec;
import java.util.Base64;
import javax.crypto.Cipher;

public class DbRSAUtils {
	
 //private static final String a = "YFerfHcGuyXedCm3e8DyBWvoeFCyk1h9Z6wWGOdoZTYQyiFO6H1cYJSHMDE0NBwUpew7GoqwH72m3AqhVm5cbrIbqAlDa2FZh7Qr5t1OlcxbaKMkn+x9Ki4KRzqHVjapXIwaUXQojqZvPN4PoExx3L/26na7cjydBX0iOIAO8mw=";
 //private static final String b = "Kq7UG64QROq+0aypnXvWrmJZ24SM3m3hWAKb9cbewrDmAOtkzKEw2eS9kjn+N+5OGsSxOvnN70yuIBBDBReZxUrSUzw0B2DSAjqLK3V/uTqTU1T1tfWjYeNtPcn1+RjgSmdC9YUv0EK8fZOhNJfWUf6j6N1fVXIjkjD/fm/Ww30=";
 //private static final String c = "KRwcxkNJy6SohZ08dA47oLbMFqh8AhGhNFyyIBcIqjrqGU3ziTfS8m9mRq9jQEOrFVFQlDGAU/XMxK630FhOk6TgbN93fNH/KWQCl/Ci8WXWmfS3yb/RhJMfZ8g2ODi/vRZbbsWv6VgVn+sLewfN2uJGvHPHRqmdJQKg0eZ0/Gg=";
 //private static final String d = "FRX99fEhUaduyArgg7vlJUjzPogerz+FQ8OqSdf5TP3+zQFZIdUPjaK9NmyvGGgTylo4VvM/zjyYZf/635vGcfLs89h49axuyKzlmQ6dIDBXQ03ixlNxVytJEG8jJZzz4OgJzJXyxVpuBHf37uVxNUHyzjfKHHFRzVfGFTw557E=";
 //private static final String e = "i9/uJTvvNt5YYj7UQUc2KIYaYsIRTQFgLxIegadXuPfqzOi3HeQjxpGX7YA89DF+B3+VLLHr5mR6Ao9itRbokr0/AwsP9slQKcrrMUnOIMb62GR6SVVRCayyHHRP/gj9CKqKmal5H2e8LEqLj9BtYCNjW07lLuU/3fb1Cnws6Vc=";
 //private static final String f = "zm8KOEPvKUF2W3pMbGm32L5xBhqkTFDdAzz0TyN/S1fp4a9Qhb9m/IGVn0tOakqqBFz6G6nT4/uNu78PVgfTJTNdAUvvAfNSjRrEm6SHOHiVUUz8MCa8AGZ319rvytJqEaydnGcPuJuJCJOCiRqGlpYCeul8GUjDnHktYi2WcQdzKU2B2lKjKlRHArIB9Z2HZnqqkhuWSTlAIBPCD7xGYcWUBeHeO3ucEJ4/2TruAN06K+Gk5RxGMkZY24SpIop2Y7483IcyNXJziI251VNGLRdVxakKeg54WwR8S8H2kGc=";

 public static byte[] getSHA1withRSA(byte[] encodedKey, byte[] data) {//a
     try {
         PKCS8EncodedKeySpec pKCS8EncodedKeySpec = new PKCS8EncodedKeySpec(encodedKey);
         KeyFactory keyFactory = KeyFactory.getInstance("RSA");
         PrivateKey privateKey = keyFactory.generatePrivate(pKCS8EncodedKeySpec);
         Signature signature = Signature.getInstance("SHA1withRSA");
         signature.initSign(privateKey);
         signature.update(data);
         return signature.sign();
     } catch (Exception e) {
         return null;
     }
 }

 public static boolean verifySHA1withRSA(byte[] encodedKey, byte[] data, byte[] sign) {//a
     try {
         KeyFactory rsa = KeyFactory.getInstance("RSA");
         Signature signature = Signature.getInstance("SHA1withRSA");
         X509EncodedKeySpec var5 = new X509EncodedKeySpec(encodedKey);
         PublicKey publicKey = rsa.generatePublic(var5);
         signature.initVerify(publicKey);
         signature.update(data);
         return signature.verify(sign);
     } catch (Exception e) {
         return false;
     }
 }

 public static Object[] a() {//a
     KeyPair keyPair = generateRSAKeyPair();
     if (keyPair == null) {
         return null;
     }
     byte[] encodePrivateKey = keyPair.getPrivate().getEncoded();
     byte[] encodePublicKey = keyPair.getPublic().getEncoded();
     Object[] arr = {encodePrivateKey,encodePublicKey};
     return arr;
 }

 public static String[] generateEncodeRSAKeyPair() {//b
     KeyPair keyPair = generateRSAKeyPair();
     if (keyPair == null) {
         return null;
     }
     String encodePrivateKey = Base64.getEncoder().encodeToString(keyPair.getPrivate().getEncoded());
     String encodePublicKey = Base64.getEncoder().encodeToString(keyPair.getPublic().getEncoded());
     String[] arr = {encodePrivateKey,encodePublicKey};
     return arr;
 }

 public static KeyPair generateRSAKeyPair() {//c
     try {
         KeyPairGenerator rsa = KeyPairGenerator.getInstance("RSA");
         SecureRandom secureRandom = SecureRandom.getInstance("SHA1PRNG", "SUN");
         secureRandom.setSeed(System.currentTimeMillis());
         rsa.initialize(1024, secureRandom);
         return rsa.generateKeyPair();
     } catch (Exception var5) {
         return null;
     }
 }

 public static byte[] rsaEncryptMode(byte[] encodedKey, byte[] input) {//b
     try {
         KeyFactory keyFactory = KeyFactory.getInstance("RSA");
         X509EncodedKeySpec keySpec = new X509EncodedKeySpec(encodedKey);
         PublicKey publicKey = keyFactory.generatePublic(keySpec);
         Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
         cipher.init(1, publicKey);
         return cipher.doFinal(input);
     } catch (Exception var6) {
         return null;
     }
 }

 public static byte[] rsaDecryptMode(byte[] encodedKey, byte[] input) {//c
     try {
         PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(encodedKey);
         KeyFactory keyFactory = KeyFactory.getInstance("RSA");
         PrivateKey privateKey = keyFactory.generatePrivate(keySpec);
         Cipher cipher = Cipher.getInstance("RSA/ECB/PKCS1Padding");
         //DECRYPT_MODE
         cipher.init(2, privateKey);
         return cipher.doFinal(input);
     } catch (Exception e) {
         return null;
     }
 }

 public static byte[] rsaDecrypt(byte[] encodedKey, byte[] input) {//d
     try {
         PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(encodedKey);
         KeyFactory keyFactory = KeyFactory.getInstance("RSA");
         PrivateKey privateKey = keyFactory.generatePrivate(keySpec);
         Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm());
         //ENCRYPT_MODE
         cipher.init(1, privateKey);
         return cipher.doFinal(input);
     } catch (Exception e) {
         return null;
     }
 }

 public static byte[] rsaDecrypt(String encodeStr, byte[] input) {//a
     try {
         byte[] bytes = Base64.getDecoder().decode(encodeStr);
         PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(bytes);
         KeyFactory keyFactory = KeyFactory.getInstance("RSA");
         PrivateKey privateKey = keyFactory.generatePrivate(keySpec);
         Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm());
         cipher.init(1, privateKey);
         return cipher.doFinal(input);
     } catch (Exception e) {
         return null;
     }
 }

 public static byte[] rsaEncrypt(byte[] encodedKey, byte[] input) {//e
     try {
         KeyFactory keyFactory = KeyFactory.getInstance("RSA");
         X509EncodedKeySpec keySpec = new X509EncodedKeySpec(encodedKey);
         PublicKey publicKey = keyFactory.generatePublic(keySpec);
         Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm());
         cipher.init(2, publicKey);
         return cipher.doFinal(input);
     } catch (Exception e) {
         return null;
     }
 }

 public static byte[] rsaEncrypt(String encodeStr, byte[] input) {//b
     try {
         byte[] var2 = Base64.getDecoder().decode(encodeStr);
         KeyFactory keyFactory = KeyFactory.getInstance("RSA");
         X509EncodedKeySpec var4 = new X509EncodedKeySpec(var2);
         PublicKey publicKey = keyFactory.generatePublic(var4);
         Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm());
         cipher.init(2, publicKey);
         return cipher.doFinal(input);
     } catch (Exception e) {
         return null;
     }
 }

 public static byte[] rsaEncrypt(String encodeStr, String encodeStr1) {//a
     try {
         byte[] input = Base64.getDecoder().decode(encodeStr1);
         byte[] encodedKey = Base64.getDecoder().decode(encodeStr);
         KeyFactory keyFactory = KeyFactory.getInstance("RSA");
         X509EncodedKeySpec keySpec = new X509EncodedKeySpec(encodedKey);
         PublicKey publicKey = keyFactory.generatePublic(keySpec);
         Cipher cipher = Cipher.getInstance(keyFactory.getAlgorithm());
         cipher.init(2, publicKey);
         return cipher.doFinal(input);
     } catch (Exception var8) {
         return null;
     }
 }

 public static byte[] digestSHA(String input) {//a
     try {
         MessageDigest digest = MessageDigest.getInstance("SHA");
         return  digest.digest(input.getBytes("UTF-8"));
     } catch (Exception var3) {
         return null;
     }
 }

 public static String getBaseName() {//d
     String var0 = "";
     byte[] var1 = rsaEncrypt(aesEncodedCatch(), "YFerfHcGuyXedCm3e8DyBWvoeFCyk1h9Z6wWGOdoZTYQyiFO6H1cYJSHMDE0NBwUpew7GoqwH72m3AqhVm5cbrIbqAlDa2FZh7Qr5t1OlcxbaKMkn+x9Ki4KRzqHVjapXIwaUXQojqZvPN4PoExx3L/26na7cjydBX0iOIAO8mw=");

     try {
         var0 = new String(var1, "UTF-8");
     } catch (UnsupportedEncodingException var3) {
         var3.printStackTrace();
     }

     return var0.substring(0, var0.indexOf(","));
 }

 public static String getResourcePath() {//e
     String var0 = "";
     byte[] var1 = rsaEncrypt(aesEncodedCatch(), "Kq7UG64QROq+0aypnXvWrmJZ24SM3m3hWAKb9cbewrDmAOtkzKEw2eS9kjn+N+5OGsSxOvnN70yuIBBDBReZxUrSUzw0B2DSAjqLK3V/uTqTU1T1tfWjYeNtPcn1+RjgSmdC9YUv0EK8fZOhNJfWUf6j6N1fVXIjkjD/fm/Ww30=");

     try {
         var0 = new String(var1, "UTF-8");
     } catch (UnsupportedEncodingException var3) {
         var3.printStackTrace();
     }

     return var0.substring(0, var0.indexOf(","));
 }

 public static String EncodedStrUTF8T1() {
     String var0 = "";
     byte[] var1 = rsaEncrypt(aesEncodedCatch(), "KRwcxkNJy6SohZ08dA47oLbMFqh8AhGhNFyyIBcIqjrqGU3ziTfS8m9mRq9jQEOrFVFQlDGAU/XMxK630FhOk6TgbN93fNH/KWQCl/Ci8WXWmfS3yb/RhJMfZ8g2ODi/vRZbbsWv6VgVn+sLewfN2uJGvHPHRqmdJQKg0eZ0/Gg=");

     try {
         var0 = new String(var1, "UTF-8");
     } catch (UnsupportedEncodingException var3) {
         var3.printStackTrace();
     }

     return var0.substring(0, var0.indexOf(","));
 }

 public static String getResourceKey() {
     String var0 = "";
     byte[] bytes = rsaEncrypt(aesEncodedCatch(), "FRX99fEhUaduyArgg7vlJUjzPogerz+FQ8OqSdf5TP3+zQFZIdUPjaK9NmyvGGgTylo4VvM/zjyYZf/635vGcfLs89h49axuyKzlmQ6dIDBXQ03ixlNxVytJEG8jJZzz4OgJzJXyxVpuBHf37uVxNUHyzjfKHHFRzVfGFTw557E=");

     try {
         var0 = new String(bytes, "UTF-8");
     } catch (UnsupportedEncodingException var3) {
         var3.printStackTrace();
     }

     return var0.substring(0, var0.indexOf(","));
 }

 public static String EncodedStrUTF8() {//h
     String var0 = "";
     byte[] bytes = rsaEncrypt(aesEncodedCatch(), "i9/uJTvvNt5YYj7UQUc2KIYaYsIRTQFgLxIegadXuPfqzOi3HeQjxpGX7YA89DF+B3+VLLHr5mR6Ao9itRbokr0/AwsP9slQKcrrMUnOIMb62GR6SVVRCayyHHRP/gj9CKqKmal5H2e8LEqLj9BtYCNjW07lLuU/3fb1Cnws6Vc=");

     try {
         var0 = new String(bytes, "UTF-8");
     } catch (UnsupportedEncodingException var3) {
         var3.printStackTrace();
     }

     return var0.substring(0, var0.indexOf(","));
 }

 public static String aesEncodedCatch() {//i
     try {
         return AesUtil.aesEncodedCatch("zm8KOEPvKUF2W3pMbGm32L5xBhqkTFDdAzz0TyN/S1fp4a9Qhb9m/IGVn0tOakqqBFz6G6nT4/uNu78PVgfTJTNdAUvvAfNSjRrEm6SHOHiVUUz8MCa8AGZ319rvytJqEaydnGcPuJuJCJOCiRqGlpYCeul8GUjDnHktYi2WcQdzKU2B2lKjKlRHArIB9Z2HZnqqkhuWSTlAIBPCD7xGYcWUBeHeO3ucEJ4/2TruAN06K+Gk5RxGMkZY24SpIop2Y7483IcyNXJziI251VNGLRdVxakKeg54WwR8S8H2kGc=", "136");
     } catch (Exception var1) {
         return null;
     }
 }
}
